package cn.caplike.demo.repository.java.concurrency.synchroniz.ed;

/**
 * 同步和非同步方法是否可以同时调用
 * 可以
 */
class RunWithNonSychronizedMethod {
    public static void main(String[] args) {
        RunWithNonSychronizedMethod runWithNonSychronizedMethod = new RunWithNonSychronizedMethod();
        new Thread(runWithNonSychronizedMethod::m1, "t1").start();
        new Thread(runWithNonSychronizedMethod::m2, "t2").start();
    }

    public synchronized void m1() {
        System.out.println(Thread.currentThread().getName() + "m1 start...");
        try {
            Thread.sleep(10000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        System.out.println(Thread.currentThread().getName() + " m1 end");
    }

    public void m2() {
        try {
            Thread.sleep(5000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        System.out.println(Thread.currentThread().getName() + " m2");
    }
}
